package com.sakura.taos.tool.manipulator.model;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

/**
 * layi 节点对象
 * @Author: Sakura
 * @Date: 2021/2/2
 */
@Data
@NoArgsConstructor
public class LayuiTree {
    /**
     * 节点标题
     */
 private String  title = "";
    /**
     * 节点唯一索引值，用于对指定节点进行各类操作	String/Number
     */
 private String  id ="";
    /**
     * 	节点字段名	String	一般对应表字段名
     */
 private String  field = "";
    /**
     * 子节点。支持设定选项同父节点	Array	[{title: '子节点1', id: '111'}]
     */
 private List<LayuiTree> children = new ArrayList<>(0);
    /**
     * 点击节点弹出新窗口对应的 url。需开启 isJump 参数	String	任意 URL
     */
 private String  href = "";
    /**
     * 节点是否初始展开，默认 false	Boolean	true
     */
 private Boolean  spread = true;
    /**
     * 节点是否初始为选中状态（如果开启复选框的话）
     */
 private Boolean  checked = false;
    /**
     * 节点是否为禁用状态。默认 false
     */
 private Boolean  disabled = false;

    /**
     * 为根节点准备,存储节点下所有库
     */
 private List<DataBaseNews> baseNews ;
    /**
     * 为子节点准备,存储子节点所有信息
     */
 private DataBaseNews baseNew ;
    /**
     * 节点所需相关的数据库名
     */
 private String dsName ;
    /**
     * 节点分组名称
     */
 private String groupName ;



    public LayuiTree(String dataName) {
        this.title = dataName;
        this.id = dataName;
        this.field = dataName;
    }

    public LayuiTree(String treeName,String dsName, List<DataBaseNews> baseNews) {
        this.dsName = dsName;
        this.title = treeName;
        this.id = treeName;
        this.field = treeName;
        this.groupName = treeName;
        this.baseNews=baseNews;
        this.children = ToLayuiTreeList(treeName,baseNews);

    }

    public LayuiTree(String treeName,DataBaseNews baseNew) {
        this.groupName = treeName;
        this.dsName = baseNew.getDsName();
        this.title = baseNew.getName();
        this.id = baseNew.getName();
        this.field = baseNew.getName();
        this.baseNew=baseNew;
    }

    public static   List<LayuiTree> ToLayuiTreeList(String treeName,List<DataBaseNews> baseNews) {
        List<LayuiTree> layuiTreeList = new ArrayList<>(baseNews.size());
        for (DataBaseNews baseNew : baseNews) {
            layuiTreeList.add(new LayuiTree(treeName,baseNew));
        }
        return layuiTreeList;
    }
}
